package com.ydlclass.converter;

import com.ydlclass.bean.Dog;
import com.ydlclass.bean.User;
import org.springframework.core.convert.converter.Converter;

public class StringToDogConverter implements Converter<String, Dog> {

	// "red | 12"
	@Override
	public Dog convert(String source) {
		if(source.contains("|")) {
			String[] split = source.split("\\|");
			if(split.length != 2){
				throw new RuntimeException("转过程发生异常，异常的source【"+source+"】");
			}
			Dog dog = new Dog();
			dog.setColor(split[0].trim());
			dog.setAge(Integer.parseInt(split[1].trim()));
			return dog;
		}
		throw new RuntimeException("转过程发生异常，异常的source【"+source+"】");
	}
}
